package com.qfedu.yanglao20admin.camera.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.entity.camera.CameraType;
import com.qfedu.yanglao20admin.camera.param.CameraTypeParam;
import com.qfedu.yanglao20admin.camera.service.CameraTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 摄像头类型信息控制层
 */
@Api(tags = "摄像头类型")
@RestController
@RequestMapping("/CameraType")
public class CameraTypeController {

    @Resource
    private CameraTypeService cameraTypeService;

    @ApiOperation(value = "分页展示摄像头类型信息", notes = "分页展示摄像头类型信息")
    @GetMapping("/page")
    public CommonResult<CameraTypeParam> page(CameraTypeParam param) {
        Page<CameraType> cameraTypePage = cameraTypeService.pageCameraType(param);
        return CommonResult.success(cameraTypePage);
    }

    @ApiOperation(value = "根据id删除摄像头类型信息", notes = "根据id删除摄像头类型信息")
    @GetMapping("/delete")
    public CommonResult deleteCameraType(@RequestParam @ApiParam("摄像头类型id") Integer id) {
        cameraTypeService.deleteById(id);
        return CommonResult.success();
    }

    @ApiOperation(value = "添加摄像头类型信息", notes = "添加摄像头类型信息")
    @PostMapping("/add")
    public CommonResult<CameraType> addCameraType(CameraType cameraType) {
        cameraTypeService.insertCameraType(cameraType);
        return CommonResult.success();
    }

    @ApiOperation(value = "根据id查询摄像头类型信息", notes = "根据id查询摄像头类型信息")
    @GetMapping("/query")
    public CommonResult queryCameraType(@RequestParam @ApiParam("摄像头类型id") Integer id) {
        CameraType cameraType = cameraTypeService.selectById(id);
        return CommonResult.success(cameraType);
    }

    @ApiOperation(value = "修改摄像头类型信息", notes = "修改摄像头类型信息")
    @PostMapping("/update")
    public CommonResult<CameraType> updateCameraType(CameraType cameraType) {
        cameraTypeService.updateCameraType(cameraType);
        return CommonResult.success();
    }

    @ApiOperation(value = "查询所有摄像头类型信息", notes = "查询所有摄像头类型信息")
    @GetMapping("/all")
    public CommonResult queryAllCameraType() {
        List<CameraType> cameraTypes = cameraTypeService.selectList();
        return CommonResult.success(cameraTypes);
    }
}
